import ChatView from '../Views/ChatView.vue'
import LoginView from '../Views/LoginView.vue'
import ForgetView from '../Views/ForgetView.vue'
import ZhuCe from '../Views/ZhuCe.vue'


const routes = [
    // 默认重定向到登录页
    { path: '/', redirect: '/Login' },

    // 登录页（简化为单一路由）
    {
        path: '/Login',
        name: 'LoginView',
        component: LoginView
    },
    // 注册页
    {
        path: '/ZhuCe',
        name: 'ZhuCeView',
        component: ZhuCe
    },
    {
        path: '/Forget',
        name: 'ForgetView',
        component: ForgetView
    },

    {
        path: '/Chat',
        name: 'ChatView',
        component: ChatView,
        beforeEnter: (_to, _from, next) => {
            // 用 userInfo 校验（登录成功已存储）
            if (localStorage.getItem('userInfo')) {
                next();
            } else {
                next('/Login');
            }
        }
    }
]

import { createRouter, createWebHashHistory } from 'vue-router'; // 改用哈希模式

const router = createRouter({
    history: createWebHashHistory(), // 替换 createWebHistory
    routes
});

export default router